/***************
 * User Networks Panel
 */
AIR2.User.Networks = function() {
    return new AIR2.UI.Panel({
        colspan: 1,
        title: 'Networks',
        showTotal: true,
        iconCls: 'air2-icon-network',
        storeData: AIR2.User.NETDATA,
        url: AIR2.User.USERURL + '/networks',
        itemSelector: '.air2-user-net',
        tpl: new Ext.XTemplate(
            '<table><tpl for="."><tr class="air2-user-net">' +
              '<td class="link">' +
                '<a class="external" target="_blank" href="{uuri_value}">' +
                  '{uuri_handle}</a>' +
              '</td>' +
            '</tr></tpl></table>',
            {compiled: true, disableFormats: true}
        ),
        editModal: {
            allowAdd: AIR2.User.USERDATA.authz.may_write,
            width: 600,
            height: 300,
            items: {
                xtype: 'air2liveeditor',
                url: AIR2.User.USERURL + '/networks',
                sortField: 'uuri_handle',
                sortDir: 'ASC',
                pageSize: 50,
                allowEdit: AIR2.User.USERDATA.authz.may_write,
                allowDelete: AIR2.User.USERDATA.authz.may_write,
                hideButtons: true,
                editForm: {
                    labelWidth: 40,
                    layout:'column',
                    items: [{
                        xtype: 'container',
                        columnWidth: .3,
                        layout: 'form',
                        items: {
                            xtype: 'air2combo',
                            name: 'uuri_handle',
                            fieldLabel: 'Type',
                            allowBlank: false,
                            disabled: true,
                            width: 100,
                            msgTarget: 'under',
                            choices: [
                                ['Facebook', 'Facebook'],
                                ['LinkedIn', 'LinkedIn'],
                                ['Twitter',  'Twitter'],
                                ['Publish2', 'Publish2'],
                                ['Personal Site', 'Personal Site'],
                                ['Work Site', 'Work Site']
                            ]
                        }
                    },{
                        xtype: 'container',
                        columnWidth: .7,
                        layout: 'form',
                        items: [{
                            xtype: 'textfield',
                            name: 'uuri_value',
                            fieldLabel: 'Link',
                            allowBlank: false,
                            width: 320,
                            msgTarget: 'under',
                            vtype: 'url'
                        }]
                    }],
                    listeners: {
                        beforeedit: function(form, rec) {
                            if (rec.phantom) form.find('name', 'uuri_handle')[0].enable();
                        }
                    }
                },
                tpl: new Ext.XTemplate(
                    '<div class="air2-user-net" style="width:100%">' +
                      '<div>' +
                        '<span class="handle">{uuri_handle}</span>' +
                        '<span class="link"><a href="{uuri_value}">{uuri_value}</a></span>' +
                      '</div>' +
                      '<div>' +
                        '<button class="air2-rowedit"></button>' +
                        '<button class="air2-rowdelete"></button>' +
                      '</div>' +
                    '</div>',
                    {compiled: true, disableFormats: true}
                )
            }
        }
    });
}
